#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    QMenuBar *menuBar = new QMenuBar();
    this->setMenuBar(menuBar);

    //创建菜单
    QMenu *menu1= new QMenu("文件");
    QMenu *menu2= new QMenu("编辑");
    QMenu *menu3= new QMenu("工具");
    menuBar->addMenu(menu1);
    menuBar->addMenu(menu2);
    menuBar->addMenu(menu3);

    //创建菜单项
    QAction *action1 = new QAction("新建");
    QAction *action2 = new QAction("打开");
    QAction *action3 = new QAction("退出");
    QAction *action4 = new QAction("复制");

    QIcon icon1(":/image/chicken.png");
    action1->setIcon(icon1);

    //添加菜单项
    menu1->addAction(action1);
    menu1->addAction(action2);
    menu1->addAction(action3);
    menu2->addAction(action4);

    //为菜单项退出绑定信号槽
    connect(action3,&QAction::triggered,this,&MainWindow::handleQuit);
    connect(action2,&QAction::triggered,this,&MainWindow::handleOpen);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handleQuit()
{
    this->close();
}

void MainWindow::handleOpen()
{
    qDebug() << "执行打开操作";
}
